"use strict";

var spawn = require('child_process').spawn;
var path = require('path');

exports.captureScreen = function(){
    return new Promise(function(resolve, reject){
        try{

            var capture;
            if (process.platform == 'darwin') {
                capture = spawn(path.join(__dirname, './bin/ScreenCapture.app/Contents/MacOS/ScreenCapture'));
            } else {
                capture = spawn(path.join(__dirname, './bin/ScrSnap.exe'));
            }

            capture.on('close', function(code){
                if(code === 0){
                    resolve(code);
                }else{
                    reject(code);
                }
            })
        }catch(e){
            reject(e);
        }
    })
}
